@extends('layouts.main')

@section('title', '合同分类列表')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  	<a href="{{ action('BaseData\CategoryContractController@create') }}" class="btn btn-primary">添加合同分类</a>
</div>
<table class="table table-bordered table-striped table-hover">
	<tr>
		<th>id</td>
		<th>分类名称</td>
		<th>是否计算规模</td>
		<th>操作</td>
	</tr>
	@forelse($models as $model)
	<tr>
		<td>{{ $model->id }}</td>
		<td>{{ $model->name }}</td>
		<td>{{ $model->is_scale == 1 ? '是' : '否' }}</td>
		<td>
			<a href="{{ action('BaseData\CategoryContractController@edit', $model) }}" class="btn btn-warning btn-sm">编辑</a>
			<button name="delete" value="{{ $model->id }}" class="btn btn-danger btn-sm">删除</button>
		</td>
	</tr>
  	@empty
  	<tr><td>暂无数据</td></tr>
  	@endforelse
</table>

<script>
      $(document).ready(function(){
        $("button[name=delete]").click(function(){
            var that = $(this);
            var id = that.attr("value");
            $.post("/base_data/category_contract/" + id, {
                '_method': 'DELETE',
                '_token': '{{ csrf_token() }}',
            }, function(data){
                switch(data.status){
                    case 0:
                        that.parent().parent('tr').remove();
                        alert("删除信息成功！");
                        break;
                }
            });
        });
    });
</script>
@endsection